{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/newsflash/newsFlashlList')}">快讯列表</a></li>
            <li class="layui-this">添加快讯</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/newsflash/postAdd')}" method="post">
                    {:token()}
                    <div class="layui-form-item">
                        <label class="layui-form-label">快讯标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="" required  lay-verify="required" placeholder="请输入快讯标题(限制12字)" class="layui-input">
                        </div>
                    </div>



                    <!--<div class="layui-form-item">-->
                        <!--<label class="layui-form-label">快讯标签</label>-->
                        <!--<input type="hidden" name="" value="" id="newId">-->
                        <!--<input type="hidden" name="label_ids" value="" id="label_ids_input"/>-->
                        <!--<div class="layui-input-block del-box">-->
                            <!--<ul class="list-label-new">-->
                            <!--</ul>-->
                            <!--<ul>-->
                                <!--<li class="add-label-btn">-->
                                    <!--<i>+</i> 添加-->
                                <!--</li>-->
                            <!--</ul>-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">快讯标签</label>
                        <input type="hidden" name="label_ids" value="" id="label_ids_input" />
                        <div class="layui-input-block">
                            <div class="layui-input labeledit-bigbox">
                                <input class="labeledit-input"/>
                            </div>
                            <div class="label_usually_use_box">
                                {foreach	$useLables	as	$key=>$value}
                                <div class="label_usually_use">{$value.name}</div>
                                {/foreach}
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">发布作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" value=""lay-verify="required" class="layui-input layui-input-inline publish_auther_name" id="ad_content_9">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">选择栏目</label>
                        <div class="layui-input-inline">
                            <select name="index_column_id"  lay-search="">
                                <option value="0">可以为空</option>
                                <!--{foreach	name="column"	item="vo"	key="k"	}-->
                                {foreach	$column	as	$key=>$value}
                                <option value="{$value.id}">{$value.knowledge_class_name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">快讯来源</label>
                        <div class="layui-input-block">
                            <input type="text" name="source" value=""lay-verify="required" class="layui-input layui-input-inline">
                        </div>
                    </div>

                    <div class="layui-form-item" id="online_time_status">
                        <label class="layui-form-label">显示设置</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="0" title="下线" checked="checked">
                            <input type="radio" name="status" value="1" title="上线">
                        </div>
                    </div>

                    <div class="layui-form-item" id="publish_by_time_box" style="display: none;">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-inline">
                            <input class="layui-input date"  placeholder="yyyy-MM-dd HH:mm:ss" name="publish_time"  value="{php} echo date('Y-m-d H:i:s',time());{/php}" type="text">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">定时发布</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="publish_by_time" value="1" lay-skin="primary" lay-filter="publish_by_time">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">收藏人数</label>
                        <div class="layui-input-block">
                            <input type="text" name="number_collection" value="{php} echo mt_rand(50, 200);{/php}" lay-verify="required" class="layui-input layui-input-inline">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读人数</label>
                        <div class="layui-input-block">
                            <input type="text" name="number_reading" value="{php} echo mt_rand(1000, 3000);{/php}" lay-verify="required" class="layui-input layui-input-inline">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">排序设置</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="0"lay-verify="required" class="layui-input layui-input-inline">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">发布平台</label>
                        <div class="layui-input-block">
                            {foreach name="$platform" item="val"}

                            <input type="checkbox" name="platform[]" lay-skin="primary"
                                   value="{$val.id}"
                                   title="{$val.platform_name}" checked="checked">
                                   {/foreach}
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">水印开关</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="close" lay-skin="switch" lay-filter="shuiying_switch" lay-text="开启|关闭">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">正文</label>
                        <div class="layui-input-block">
                            <textarea id="content_box" placeholder="" class="layui-textarea" name="synopsis"></textarea>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="">保存</button>
                            <div class="layui-btn" id="preview_btn">预览</div>
                            <input type="hidden" id="preview_data"/>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="iframe-bigbox" style="display: none;">
    <input id="packdata" type="hidden">
    <input id="iframe_url" type="hidden" value="__CSS__/wechat/detail_kuaixun.html"/>
    <div class="iframe-bigbox-mask"></div>
    <iframe id="iframe_box" src="" style=""></iframe>
</div>
{/block}
{block name="js"}
<script src="__JS__/ueditor/ueditor.config.js"></script>
<script src="__JS__/ueditor/ueditor.all.min.js"></script>
{/block}
{block name="script"}
<script>
    labelUsuallyUse();
    content_init("shuiying_switch");
    publish_by_time();
    $(function() {
        //预览
        $("#preview_btn").on("click",function () {
            var packdata = {};
            packdata.name = $("input[name='name']").val();//标题
            packdata.author = $("input[name='author']").val();//作者
//            packdata.create_time = $("input[name='publish_time']").val();//发布时间
            packdata.content = $("textarea[name='synopsis']").parents(".layui-input-block").find("iframe")[0].contentWindow.document.body.innerHTML;//文章
            packdata.label_arr = [];//标签
            for(var i = 0; i < $(".list-label-new li").length; i++){
                packdata.label_arr.push({"label_name":$(".list-label-new li").eq(i).attr("data-name")});
            }
            packdata.img = "";//作者头像
            $("#packdata").val(JSON.stringify(packdata));
            $(".iframe-bigbox").fadeIn(300);
            $("#iframe_box").attr({"src":$("#iframe_url").val()});
            $(".iframe-bigbox-mask").on("click",function () {
                $(".iframe-bigbox").fadeOut(300);
                $("#iframe_box").attr({"src":""});
            });
        });
      relpace_link();
      var input = $("label:contains(发布作者)").next('.layui-input-block').find('input');
      console.log(input)
      var source = $("label:contains(快讯来源)").next('.layui-input-block').find('input');
      $(input).keyup(function() {
        source.val($(this).val())
      })


        layui.upload({
            url: "/api/file_upload/upload",
            before: function(obj){
                _loadshow("正在上传");
            },
            success: function (data) {
                _loadhide();
                if (data.error === 0 && data.type === 'image') {
                    document.getElementById('Cover_Ad').value = data.url;
                    var _ad_index_img_box = $(".ad_index_img_box");//上传图片显示盒子
                    _ad_index_img_box.empty();
                    _ad_index_img_box.append(
                            '<img style="display: block; width: 92px;" src="' + data.url + '"/>'
                    );
                } else {
                    layer.msg(data.message);
                }
            }
        });

        $('.date').on('click', function () {
            laydate({
                elem: this
                ,format: 'YYYY-MM-DD hh:mm:ss'
                ,type: 'datetime'
            })
        });
    });
    labeledit_fun();

</script>

{/block}
